package com.yk.web.controller;

import java.util.List;

import com.yk.course.domain.CourseInfoChild;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.yk.common.annotation.Log;
import com.yk.common.enums.BusinessType;
import com.yk.course.service.ICourseInfoChildService;
import com.yk.common.core.controller.BaseController;
import com.yk.common.core.domain.AjaxResult;
import com.yk.common.utils.poi.ExcelUtil;
import com.yk.common.core.page.TableDataInfo;

/**
 * 学生订购课程Controller
 * 
 * @author xufei
 * @date 2025-05-03
 */
@Controller
@RequestMapping("/course/courseInfoChild")
public class CourseInfoChildController extends BaseController
{
    private String prefix = "course/courseInfoChild";

    @Autowired
    private ICourseInfoChildService courseInfoChildService;

    @RequiresPermissions("course:courseInfoChild:view")
    @GetMapping()
    public String courseInfoChild()
    {
        return prefix + "/courseInfoChild";
    }

    /**
     * 查询学生订购课程列表
     */
    @RequiresPermissions("course:courseInfoChild:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CourseInfoChild courseInfoChild)
    {
        startPage();
        List<CourseInfoChild> list = courseInfoChildService.selectCourseInfoChildList(courseInfoChild);
        return getDataTable(list);
    }

    /**
     * 导出学生订购课程列表
     */
    @RequiresPermissions("course:courseInfoChild:export")
    @Log(title = "学生订购课程", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CourseInfoChild courseInfoChild)
    {
        List<CourseInfoChild> list = courseInfoChildService.selectCourseInfoChildList(courseInfoChild);
        ExcelUtil<CourseInfoChild> util = new ExcelUtil<CourseInfoChild>(CourseInfoChild.class);
        return util.exportExcel(list, "学生订购课程数据");
    }

    /**
     * 新增学生订购课程
     */
    @RequiresPermissions("course:courseInfoChild:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存学生订购课程
     */
    @RequiresPermissions("course:courseInfoChild:add")
    @Log(title = "学生订购课程", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CourseInfoChild courseInfoChild) throws Exception {
        return toAjax(courseInfoChildService.insertCourseInfoChild(courseInfoChild));
    }

    /**
     * 修改学生订购课程
     */
    @RequiresPermissions("course:courseInfoChild:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        CourseInfoChild courseInfoChild = courseInfoChildService.selectCourseInfoChildById(id);
        mmap.put("courseInfoChild", courseInfoChild);
        return prefix + "/edit";
    }

    /**
     * 修改保存学生订购课程
     */
    @RequiresPermissions("course:courseInfoChild:edit")
    @Log(title = "学生订购课程", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CourseInfoChild courseInfoChild)
    {
        return toAjax(courseInfoChildService.updateCourseInfoChild(courseInfoChild));
    }

    /**
     * 删除学生订购课程
     */
    @RequiresPermissions("course:courseInfoChild:remove")
    @Log(title = "学生订购课程", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(courseInfoChildService.deleteCourseInfoChildByIds(ids));
    }
}
